<template>
  <!-- 用户管理页面 -->
  <div class="page-container">
    <el-card class="main-card">
      <template #header>
        <span class="main-title">用户管理</span>
        <el-button type="primary" size="small" style="float:right" @click="showAdd = true" class="main-btn">新增用户</el-button>
      </template>
      <!-- 用户列表表格 -->
      <el-table :data="users" style="width: 100%; margin-top: 16px;" stripe highlight-current-row>
        <el-table-column type="index" label="序号" width="80" align="center" />
        <el-table-column prop="name" label="姓名" width="100" />
        <el-table-column prop="gender" label="性别" width="80" />
        <el-table-column prop="role" label="角色" width="100" />
        <el-table-column prop="phone" label="手机号" width="130" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button size="small" @click="editUser(scope.$index)" class="main-btn">编辑</el-button>
            <el-button size="small" type="danger" @click="deleteUser(scope.$index)" class="main-btn danger-btn">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 新增/编辑用户弹窗 -->
      <el-dialog :title="editIndex === -1 ? '新增用户' : '编辑用户'" v-model="showAdd" width="400px" class="main-dialog">
        <el-form :model="form" label-width="80px">
          <el-form-item label="姓名"><el-input v-model="form.name" /></el-form-item>
          <el-form-item label="性别">
            <el-select v-model="form.gender"><el-option label="男" value="男" /><el-option label="女" value="女" /></el-select>
          </el-form-item>
          <el-form-item label="角色"><el-input v-model="form.role" /></el-form-item>
          <el-form-item label="手机号"><el-input v-model="form.phone" /></el-form-item>
        </el-form>
        <template #footer>
          <el-button @click="showAdd = false">取消</el-button>
          <el-button type="primary" @click="saveUser" class="main-btn">保存</el-button>
        </template>
      </el-dialog>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
// 用户数据（前端模拟）
const users = ref([
  { name: '张三', gender: '男', role: '医生', phone: '13800138000' },
  { name: '李四', gender: '女', role: '护士', phone: '13900139000' },
  { name: '王五', gender: '男', role: '管理员', phone: '13700137000' }
])
const showAdd = ref(false)
const editIndex = ref(-1)
const form = ref({ name: '', gender: '', role: '', phone: '' })
// 编辑用户
function editUser(index) {
  editIndex.value = index
  Object.assign(form.value, users.value[index])
  showAdd.value = true
}
// 删除用户
function deleteUser(index) {
  users.value.splice(index, 1)
  ElMessage.success('删除成功')
}
// 保存用户
function saveUser() {
  if (!form.value.name || !form.value.gender || !form.value.role || !form.value.phone) {
    ElMessage.error('请填写完整信息')
    return
  }
  if (editIndex.value === -1) {
    users.value.push({ ...form.value })
    ElMessage.success('新增成功')
  } else {
    users.value[editIndex.value] = { ...form.value }
    ElMessage.success('编辑成功')
  }
  showAdd.value = false
  editIndex.value = -1
  form.value = { name: '', gender: '', role: '', phone: '' }
}
</script>

<style scoped>
.page-container {
  padding: 32px;
  background: linear-gradient(135deg, #e3f0ff 0%, #f5f7fa 100%);
  min-height: 100vh;
}
.main-card {
  border-radius: 16px;
  box-shadow: 0 8px 32px 0 rgba(80,120,200,0.10), 0 1.5px 8px 0 rgba(80,120,200,0.08);
  transition: box-shadow 0.3s;
}
.main-card:hover {
  box-shadow: 0 12px 40px 0 rgba(80,120,200,0.16), 0 2px 12px 0 rgba(80,120,200,0.10);
}
.main-title {
  font-size: 22px;
  font-weight: 600;
  color: #1976d2;
  letter-spacing: 1px;
}
.main-btn {
  border-radius: 8px;
  background: linear-gradient(90deg, #42a5f5 0%, #1976d2 100%);
  font-weight: 600;
  letter-spacing: 1px;
  border: none;
  transition: background 0.2s, box-shadow 0.2s;
  margin-left: 8px;
}
.main-btn:hover {
  background: linear-gradient(90deg, #1976d2 0%, #42a5f5 100%);
  box-shadow: 0 4px 16px 0 rgba(33,150,243,0.12);
}
.danger-btn {
  background: linear-gradient(90deg, #ef5350 0%, #d32f2f 100%);
  color: #fff;
}
.danger-btn:hover {
  background: linear-gradient(90deg, #d32f2f 0%, #ef5350 100%);
}
.el-table {
  border-radius: 10px;
  overflow: hidden;
}
.el-table__row:hover {
  background: #e3f2fd !important;
}
.main-dialog :deep(.el-dialog__body) {
  border-radius: 12px;
}
</style> 